import {loadingFull} from '@/utils'
import { ElMessage, ElLoading } from 'element-plus';
const ConfigObj = {
    noInterceptArr: ['auth'],    // 请求白名单  无需token的请求接口
    options: {
        baseURL: process.env.NODE_ENV === 'production' ? window.global_API.prodUrl : window.global_API.devUrl,
        headers: {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*'
        },
        // responseType: 'text',
        method: 'GET',
        // dataType: 'json',
        // custom: {},
        timeout: 60000,
    },
    loading: {
        limitTime: 3000,
        show: () => {
            loadingFull.open();
        },
        hide: () => {
            loadingFull.close();
        }
    },
    // 请求默认值
    tipConfig: {
        hideMsg: false,     // 请求成功时， 是否弹框提示信息
        codeFile: false,     // 是否是返回的文件或图片
        upLoadForm: false,  // form传FormData构造函数
	},
    keyTipConfig: [
        { code: '200', type:'success', message: '请求成功'},
        { code: '500', type:'error', message: '网络异常，请稍后重试500'},
        { code: '401', type:'error', message: '网络异常，请稍后重试401'},
        { code: '406', type:'error', message: '用户登录已过期，请重新登录'},
    ],
    tipShow: (res, tipConfig, type) => {
        let i = ConfigObj.keyTipConfig.find(j => j.code == res.code) || {};
        if(type == 'success'){
            if(tipConfig.hideMsg){
                ElMessage({
                    showClose: true,
                    message: (res && (res.msg || i.message || '请求成功')) || '请求成功',
                    type: 'success',
                })
            }
        } else if(type == 'error') {
            ElMessage({
                showClose: true,
                message: (res && (res.data.msg || i.message)) || "网络异常，请稍后重试" + res.code,
                type: 'error',
            })
        }else{
            ElMessage({
                showClose: true,
                message: (res && (res.msg || i.message)) || "网络异常，请稍后重试" + res.code,
                type: i.type,
            })
        }
    }
}

export default ConfigObj